import java.sql.*;

public class DB {
	private static String host = "dryad09.inf.ethz.ch";
	private static int port = 5132;
	private static String database = "tpch";
	private static String username = "group3705";
	private static String password = "group3705";
	
	public static Connection Connect() {
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
			System.out.println("Where is your PostgreSQL JDBC Driver? Include in your library path!");
			e.printStackTrace();
			return null;
		}
		
		Connection connection = null;
		try {
			connection = DriverManager.getConnection("jdbc:postgresql://" + host + ":" + port + "/" + database, username, password);
		} catch (SQLException e) {
			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
			return null;
		}
		if (connection == null) {
			System.out.println("Failed to make connection!");
		}
		return connection;
	}
	
	public static void Disconnect(Connection connection) {
		try {
			connection.close();
		} catch(SQLException e) {
			System.out.println("Disconnection Failed! Check output console");
			e.printStackTrace();
		}
	}
}
